﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Visitor;

namespace ASTClass
{
    class BoolAST : TerminalAST
    {
        public BoolAST() : base() { name = "Bool"; }
        public BoolAST(AST parent) : base(parent) { name = "Bool"; }

        public override AST Clone()
        {
            BoolAST ast = new BoolAST();
            ast.operators = operators;
            foreach (AST c in children)
                ast.children.Add(c.Clone());

            return ast;
        }

        public override void CodeGen(Taste.SymbolTable st, Taste.CodeFileGen cfg)
        {
            if (this.Value.CompareTo("true") == 0)
            {
                cfg.AddCommand("li", "$t0, 1");
            }
            else if (this.Value.CompareTo("false") == 0)
            {
                cfg.AddCommand("li", "$t0, 0");
            }
            cfg.AddCommand("subu", "$sp, $sp, 4");
            cfg.AddCommand("sw", "$t0, 0($sp)");
        }

        #region Visitor pattern

        public override void Accept(IVisitor visitor)
        {
            visitor.Visit(this);
        }

        #endregion Visitor pattern
    }
}
